package com.wangyuhang.controller;

import com.wangyuhang.domain.User;
import com.wangyuhang.service.userService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/users")
public class UesrController {
    @Autowired
    private userService service;

    @GetMapping()
    public List<User> finAll() {
        List<User> list = service.findAll();
        return list;
    }

    /*按id查询*/
    @GetMapping("/{id}")
    public User finById(@PathVariable Integer id) {
        User user = service.findById(id);
        return user;
    }
    @PostMapping()
    public boolean Insert(@RequestBody User user){
        int i = service.UserInsert(user);
        boolean flag=false;
        if (i>0){
            flag=true;
        }else {
            flag=false;
        }
       return flag;
    }
}
